package com.xuqi.W3;

import android.util.Log;

/**
 * Wrapper API for logging
 *
 * @note	use W3_LOG_LEVEL to define LOG LEVEL (default: W3_LOG_LEVEL_1)
 */
public class W3Log {

	protected final static int W3_LOG_LEVEL_0 = 0; ///< show nothing
	protected final static int W3_LOG_LEVEL_1 = 1; ///< show error
	protected final static int W3_LOG_LEVEL_2 = 2; ///< show error, warn, 
	protected final static int W3_LOG_LEVEL_3 = 3; ///< show error, warn, info
	protected final static int W3_LOG_LEVEL_4 = 4; ///< show all (error, warn, info, debug)
	
	protected final static int W3_LOG_LEVEL = W3_LOG_LEVEL_4; ///< default: W3_LOG_LEVEL_1
	
	protected final static String TAG = "Navi"; ///< LOG TAG
		
	/**
	 * Constructor
	 */
	public W3Log() {
	}
	
	/**
	 * log DEBUG message
	 * @param msg : The message to log
	 */
	public static void d(String msg) {
		if (W3_LOG_LEVEL > W3_LOG_LEVEL_3) {
			Log.d(TAG, wrapperMsg(msg));
		}
	}
	
	/**
	 * log INFO message
	 * @param msg : The message to log
	 */
	public static void i(String msg) {
		if (W3_LOG_LEVEL > W3_LOG_LEVEL_2) {
			Log.i(TAG, wrapperMsg(msg));
		}
	}
	
	/**
	 * log WARN message
	 * @param msg : The message to log
	 */
	public static void w(String msg) {
		if (W3_LOG_LEVEL > W3_LOG_LEVEL_1) {
			Log.w(TAG, wrapperMsg(msg));
		}
	}
	
	/**
	 * log ERROR message
	 * @param msg : The message to log
	 */
	public static void e(String msg) {
		if (W3_LOG_LEVEL > W3_LOG_LEVEL_0) {
			Log.e(TAG, wrapperMsg(msg));
		}
	}
	
	/**
	 * Wrapper the message
	 * @param msg : The message to wrapper
	 */
	protected static String wrapperMsg(String msg) {
		StackTraceElement elem = new Throwable().fillInStackTrace().getStackTrace()[2];
		return String.format("[W3JVM] %s (%s:%d)", msg, elem.getFileName(), elem.getLineNumber());
	}
}
